import {Component, OnInit, Input, Output, EventEmitter, ViewChild} from '@angular/core';
import {ConfirmCheckoutModalViewComponent} from "../confirm-checkout-modal-view/confirm-checkout-modal-view.component";
import {CONTRACT} from "../../service/contract.service";
import {WfToast} from "../../utils/toast.utils";
import {LocalStorage} from "../../app.local-storage";

@Component({
  selector: 'app-checkout-modal-view',
  templateUrl: './checkout-modal-view.component.html',
  styleUrls: ['./checkout-modal-view.component.scss']
})
export class CheckoutModalViewComponent implements OnInit {
  @ViewChild(ConfirmCheckoutModalViewComponent) public confirmCheckoutModal:any;
  @Input('showModal') public isModalShown: boolean = false;
  @Output('modalClose') public modalClose = new EventEmitter();
  @Input()
  contractId:number;

  constructor(private contract:CONTRACT,
              private toast:WfToast,
              private localStorage:LocalStorage) { }

  ngOnInit() {

  }

  public showModal(): void {
    this.isModalShown = true;
  }

  public onHidden(): void {
    this.isModalShown = false;
  }
  showConfirmCheckoutModal(item:any){
    let reqData:any={
      // 1-退租，2-续约，3-换房，4-转租
      id:this.contractId,
      operation:1
    }
    let close = this.modalClose;
    this.contract.Checkout(reqData,(res:any = Object)=>{
      if(res =='OK'){
        this.confirmCheckoutModal.isModalShown = true;
        close.emit(false);
      }
    });
  }
  closeConfirmCheckoutModal(result:any){
    this.confirmCheckoutModal.onHidden();
  }
}
